<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "goods".
 *
 * @property int $goods_id
 * @property string $goods_name
 * @property string $goods_price
 * @property string $goods_stock
 * @property string $goods_img
 * @property int $brand_id
 * @property int $type_id
 */
class Goods extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'goods';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['brand_id', 'type_id'], 'integer'],
            [['goods_name'], 'string', 'max' => 30],
            [['goods_price', 'goods_stock'], 'string', 'max' => 5],
            [['goods_img'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'goods_id' => 'Goods ID',
            'goods_name' => 'Goods Name',
            'goods_price' => 'Goods Price',
            'goods_stock' => 'Goods Stock',
            'goods_img' => 'Goods Img',
            'brand_id' => 'Brand ID',
            'type_id' => 'Type ID',
        ];
    }
    //商品表查询数据
    public function findData($id)
    {
        return Goods::find()
        ->innerjoin("brand","goods.brand_id=brand.brand_id")
        ->innerjoin("type","goods.type_id=type.type_id")
        ->where(['goods_id' => $id])
        ->asArray()
        ->one();

    }
}
